<template>
  <view class="content">
    <view class="login">
      <view class="login-top">注册</view>
      <view class="login-center clearfix">
        <view class="login-center-img"
          ><image src="../../static/name.png"
        /></view>
        <view class="login-center-input">
          <input placeholder="请输入您的手机号" v-model="phone" />
        </view>
      </view>
      <view class="login-center clearfix">
        <view class="login-center-img"
          ><image src="../../static/password.png"
        /></view>
        <view class="login-center-input">
          <input
            type="password"
            placeholder="请输入您的密码"
            v-model="password"
          />
        </view>
      </view>
      <view class="login-center clearfix">
        <view class="login-center-img"
          ><image src="../../static/password.png"
        /></view>
        <view class="login-center-input">
          <input
            type="password"
            placeholder="请再次输入您的密码"
            v-model="password1"
          />
        </view>
      </view>
      <u-toast ref="notice"></u-toast>

      <view class="tologin" @click="tologin">
        <text>去登陆~</text>
      </view>

      <view class="login-button" @click="submit">注册</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      phone: "",
      password: "",
      password1: "",
      type: "",
    };
  },
  onLoad(option) {
    this.type = option.type ? option.type : "";
	console.log(this.type)

	return false
  },
  methods: {
    tologin() {
      uni.$u.route({
        url: "pages/user/login",
        params: {
          type: this.type,
        },
      });
    },

    async submit() {
      let data = {
        mobile: this.phone,
        password: this.password,
        password1: this.password1,
        type: this.type,
      };

      if (data.password1.trim().length === 0) {
        this.$refs.notice.show({
          type: "error",
          message: "确认密码不能为空",
          duration: 1200,
        });

        return false;
      }

      if (data.password.trim().length === 0) {
        this.$refs.notice.show({
          type: "error",
          message: "密码不能为空",
          duration: 1200,
        });

        return false;
      }

      if (data.mobile.trim().length === 0) {
        this.$refs.notice.show({
          type: "error",
          message: "手机号不能为空",
          duration: 1200,
        });

        return false;
      }

      let result = await this.$u.api.user.register(data);
      if (result.code) {
        this.$refs.notice.show({
          type: "success",
          message: result.msg,
          duration: 1200,
          complete: () => {
            uni.$u.route({
              url: "pages/user/login",
              params: {
                phone: this.phone,
                password: this.password,
                type: this.type,
              },
            });
          },
        });
      } else {
        this.$refs.notice.show({
          type: "warning",
          message: result.msg,
          duration: 1200,
          complete: () => {
            uni.$u.route({
              url: "pages/user/login",
              params: {
                phone: this.phone,
                password: this.password,
                type: this.type,
              },
            });
          },
        });
      }
    },
    goto() {
      if (this.type == "business") {
        uni.$u.route({
          url: "pages/test/business",
          params: {
            type: this.type,
          },
        });
      } else if (this.type == "seller") {
        uni.$u.route({
          url: "pages/test/seller",
          params: {
            type: this.type,
          },
        });
      } else {
        uni.$u.route({
          url: "pages/test/merchant",
          params: {
            type: this.type,
          },
        });
      }
    },
  },
};
</script>

<style lang="scss">
* {
  box-sizing: content-box;
}

.clearfix:after {
  visibility: hidden;
  display: block;
  font-size: 0;
  content: " ";
  clear: both;
  height: 0;
}
.cli {
  clear: both;
  font-size: 0;
  height: 0;
  overflow: hidden;
  display: block;
}
.lclear {
  clear: left;
  font-size: 0;
  height: 0;
  overflow: hidden;
}
.fl {
  float: left;
}
.fr {
  float: right;
}
.content {
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-y: hidden;
}
.login {
  width: 350px;
  border-radius: 5px;
  height: 500px;
  background: white;
}
.login-top {
  font-size: 24px;
  margin-top: 100px;
  padding-left: 40px;
  box-sizing: border-box;
  color: #333333;
  margin-bottom: 50px;
}
.login-center {
  width: 100%;
  box-sizing: border-box;
  padding: 0 40px;
  margin-bottom: 30px;
}
.login-center-img {
  width: 40rpx;
  height: 40rpx;
  float: left;
  margin-top: 5px;
}
.login-center-img > image {
  width: 100%;
  height: 100%;
}
.login-center-input {
  float: left;
  width: 230px;
  margin-left: 15px;
  height: 30px;
  position: relative;
}
.login-center-input input {
  z-index: 2;
  transition: all 0.5s;
  padding-left: 10px;
  color: #333333;
  width: 100%;
  height: 30px;
  border: 0;
  border-bottom: 1px solid #cccccc;
  border-top: 1px solid #ffffff;
  border-left: 1px solid #ffffff;
  border-right: 1px solid #ffffff;
  box-sizing: border-box;
  outline: none;
  position: relative;
}
.login-center-input input:focus {
  border: 1px solid dodgerblue;
}
.login-center-input-text {
  background: white;
  padding: 0 5px;
  position: absolute;
  z-index: 0;
  opacity: 0;
  height: 20px;
  top: 50%;
  margin-top: -10px;
  font-size: 14px;
  left: 5px;
  color: dodgerblue;
  line-height: 20px;
}

.login-button {
  cursor: pointer;
  width: 350px;
  text-align: center;
  height: 40px;
  line-height: 40px;
  background-color: #5ac725;
  border-radius: 5px;
  margin-top: 50px;
  color: white;
}

.tologin {
  color: #5ac725;
  padding-left: 35px;
  font-size: 13px;
}
</style>

